const {mongoose} = require('./db')

const Schema = mongoose.Schema

//用户表
const userSchema = new Schema({
    username: String,//用户名
    password: String,//密码
    locking: Boolean,  //是否锁定
    realName: String,//真实姓名
    introduce: String,//介绍
    imgpath: String,//头像
    createTime: {
        type: Date,
        default: new Date()
    },
    role_id: {          // 角色id
        type: mongoose.Types.ObjectId,
        ref: 'role'
    },

    login: Boolean,    //是否限制登录
    superior: String,   //直接上级
    remarks: String, //备注
}, {versionKey: false})

//角色表
const RoleSchema = new Schema({
    roleName: String,
    introduce: String,
    moudule_id: {
        type: mongoose.Types.ObjectId,
        ref: "moudule"
    },
    menu_id: Array
}, {versionKey: false})

//模块表
const mouduleSchema = new Schema({
    MouduleName: String,
    imgpath: String,//图标
    menu_id: Array
}, {versionKey: false})
//导航栏(权限表)
const menuSchema = new Schema({
    menuName: String,
    menu_key: String,
    parent_id: {
        type: mongoose.Types.ObjectId,
        ref: "menu"
    },
    icon:String,
    desc: Number
}, {versionKey: false})

//部门表
const deparmentSchema = new Schema({
    departentName: String,
    introduce: String,
    parent_id: {
        type: mongoose.Types.ObjectId,
        ref: "department"
    },
    parent: Number,
    jobNumber: String,
    jobName: String,
    jobIfy: String,
}, {versionKey: false})

// 任务表
const taskdata = new Schema({
    taskname: String,
    faname: String,
    tasklevel: String,
    taskstart: String,
    person: String,
    xieperson: String,
    zhiperson: String,
    topdata: Date,
    enddata: Date,
    taskexplain: String,
}, {versionKey: false})

//新闻表
const news = new Schema({
    title: String,
    datetime: Date,
    createuser: {
        type: mongoose.Types.ObjectId,
        ref: "user"
    },
})

//公共表
const noticeSchema = new Schema({
    noticeName: String,
    parent: Number, //级别
    personnel: String, //接收人员
    open: Boolean,  //是否公开
    notice_id: {
        type: mongoose.Types.ObjectId,
        ref: "notice"
    },
    createTime: {
        type: Date,
        default: new Date()
    },
    createuser: {
        type: mongoose.Types.ObjectId,
        ref: "user"
    },
    all: {
        type: mongoose.Types.ObjectId,
        ref: "notice"
    }
}, {versionKey: false})


const userModel = mongoose.model('user', userSchema, 'user')
const roleModel = mongoose.model('role', RoleSchema, 'role')
const mouduleModel = mongoose.model('moudule', mouduleSchema, 'moudule')
const menuModel = mongoose.model('menu', menuSchema, 'menu')
const departModel = mongoose.model('department', deparmentSchema, 'department')
const taskdataModel = mongoose.model('taskdata', taskdata, 'taskdata')
const newsModel = mongoose.model('news', news, 'news')
const noticeModel = mongoose.model('notice', noticeSchema, 'notice')




module.exports = {
    userModel, mouduleModel, roleModel, menuModel, departModel, taskdataModel, newsModel, noticeModel
}